#!/usr/bin/env bash
# 生成可执行文件
set -eo pipefail

# 错误处理：输出错误信息并退出
trap 'echo "错误: 在行 ${LINENO} 执行命令失败 - 命令: $BASH_COMMAND, 退出码: $?" >&2' ERR


if ! pip show pyinstaller &> /dev/null; then
    echo "PyInstaller 未安装，正在安装..."
    pip install pyinstaller
else
    echo "PyInstaller 已安装"
fi

rm -fr build
rm -fr dist
pyinstaller --onefile clean4llm.py --icon clean4llm.ico
# 根据当前平台自动添加后缀
if [[ "$OSTYPE" == "darwin"* ]]; then
    echo "生成可执行文件成功 - dist/clean4llm.app"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
    echo "生成可执行文件成功 - dist/clean4llm"
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
    echo "生成可执行文件成功 - dist/clean4llm.exe"
else
    echo "生成可执行文件成功 - dist/clean4llm"
fi

